<?php
class MSEP_Database extends MSEP_Object
{


      private $database;



      public function __init(MSEP $core)
      {
            global $database;

            $this->core = $core;

            $this->database = $database;

            $this->core->stores(false, 'db_chain');
      }



      function call($method, $arguments)
      {
            $method = str_replace(__CLASS__."::", "", $method);
            return call_user_func_array(array($this->database, "database_{$method}"), $arguments);
      }



      function connect($database_host, $database_username, $database_password)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function select($database_name)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function query($database_query, $store = false)
      {
            $arguments = func_get_args();

            if ($store)
            {
                  $this->core->stores(true, 'db_chain');
                  $this->core->stores($this->call(__METHOD__, $arguments), 'db_resource');

                  return $this;
            }
            else
            {
                  return $this->call(__METHOD__, $arguments);
            }
      }



      function fetch_array($database_result)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function num_fields($database_result)
      {
            if (!is_resource($database_result)) return FALSE;
            return mysql_num_fields($database_result);
      }



      function fetch_assoc($database_result = null)
      {
            $arguments = func_get_args();

            if ($this->core->__('db_chain'))
            {
                  $arguments[0] = $this->core->__('db_resource');

                  $this->core->removes('db_resource');

                  $this->core->stores(false, 'db_chain');
            }

            return $this->call(__METHOD__, $arguments);
      }



      function num_rows($database_result)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function boolean($database_result = null)
      {
            if ($this->core->__('db_chain'))
            {
                  $database_result = $this->core->__('db_resource');

                  $this->core->removes('db_resource');

                  $this->core->stores(false, 'db_chain');
            }

            $data = $this->fetch_assoc($database_result);

            if ($data["count(*)"] > 0)
            {
                  return true;
            }

            return false;
      }



      function affected_rows()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function free_result($database_result)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function set_charset($charset)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function escape($unescaped_string)
      {
            $arguments = func_get_args();
            return $this->call("real_escape_string", $arguments);
      }



      function insert_id()
      {
            if ($this->core->__('db_chain'))
            {
                  $this->core->removes('db_resource');

                  $this->core->stores(false, 'db_chain');
            }

            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function error()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function load_all()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function load_all_assoc($key_column)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function close()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function benchmark_sort()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function get_client_info()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function get_host_info()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function get_proto_info()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function get_server_info()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function log_stats()
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }



      function log_stats_cleanup($not_slow = true)
      {
            $arguments = func_get_args();
            return $this->call(__METHOD__, $arguments);
      }


}
?>